<?php
/**
 * Created by PhpStorm.
 * User: jimmyhsu
 * Date: 2016/10/12
 * Time: 下午11:44
 */
include ("conn.php");
$name = $_POST['name'];
$deviceid = $_POST['deviceid'];
$itemid = $_POST['itemid'];
$itemtype = $_POST['itemtype'];
$checkSql = "select * from userinfo where name = '$name' and deviceid = '$deviceid'";
$checkRs = mysql_query($checkSql);
if (mysql_num_rows($checkRs) == 0) {
    die("invalid visit");
}
$row = mysql_fetch_array($checkRs);
$userid = $row['id'];
$content = $_POST['comment'];
$time = time()*1000;
$checkRw = mysql_fetch_array($checkRs);
$userUrl = 'userimage/'.$userid.'.jpg';
$insertsql = "insert into commenttb (id, name, time, userhead, content, attachedid, attachedtype)
 values (NULL, '$name', $time, '$userUrl', '$content', $itemid, $itemtype)";
if (mysql_query($insertsql)) {
    echo "success";
}else{
    echo "fail";
}